<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('通知公告列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="notice-form">
                <div class="select-list">
                    <ul>
                        <li>
                            消息标题：<input type="text" name="noticeTitle"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-info multiple" onclick="markRead()">
                <i class="fa fa-check"></i> 标记已读
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="message:notice:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('message:notice:edit')}]];
    var removeFlag = [[${@permission.hasPermi('message:notice:remove')}]];
    var reads = [[${@dict.getType('read_status')}]];
    var prefix = ctx + "back/message/notice";

    /*标记已读*/
    function markRead() {
        var rows = $.table.selectFirstColumns();
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $.modal.confirm("确认标记已读选中" + rows.length + "条消息吗?", function () {
            $.modal.loading("正在保存...");
            $.post(prefix + "/readUser", {ids: rows.join()}, function (result) {
                if (result.code == web_status.SUCCESS) {
                    $.modal.alertSuccess(result.msg)
                    $.table.refresh();
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            });
        });
    }

    /*消息详细*/
    function detail(noticeId) {
        var url = prefix + '/detail/' + noticeId;
        $.modal.openTab("消息内容", url);
        $.table.refresh();
    }

    $(function () {
        var options = {
            url: prefix + "/userList",
            removeUrl: prefix + "/removeUser",
            modalName: "站内消息",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '序号'
                },
                {
                    field: 'messageTypeName',
                    title: '类型',
                    align: 'center'
                },
                {
                    field: 'noticeTitle',
                    title: '标题',
                    formatter:function (value,row,index) {
                        return '<a href="javascript:void(0)" onclick="detail(\'' + row.noticeId + '\')">' + value + '</a>';
                    }
                },
                {
                    field: 'isRead',
                    title: '阅读状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(reads, value);
                    }
                },
                {
                    field: 'createBy',
                    title: '发送人'
                },
                {
                    field: 'createTime',
                    title: '发送时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
</script>
</body>
</html>